package egean.pad.datacommunication;

import java.util.ArrayList;
import java.util.HashMap;


import egean.pad.tool.Scales;

import android.content.Context;
import android.widget.ListView;
import android.widget.SimpleAdapter;


public class ScalesHistoryList {
	public ScalesHistoryList(Context context,ListView list,Scales[] scales_data,String sex){
		ArrayList m_arrayadapter = new ArrayList<HashMap<String, String>>();
		if(scales_data != null){
			int length = scales_data.length;
			for (int i = 0; i < length; i++) {
				HashMap<String, String> map = new HashMap<String, String>();

				map.put("time",scales_data[i].KEY_TIME);
				map.put("scales",scales_data[i].KEY_SCALES+" KG");
				map.put("muscle", scales_data[i].KEY_MUSCLE_CONTENT+" %");
				map.put("moisture",scales_data[i].KEY_MOISTURE+" %");
				map.put("fat_percentage",scales_data[i].KEY_FAT_PERCENTAGE+" %");
				map.put("calorie",scales_data[i].KEY_CALORIE+" CAL");
				map.put("bmr",scales_data[i].KEY_BMR+" CAL");
				map.put("body",judgeBody(context,Double.parseDouble(scales_data[i].KEY_MUSCLE_CONTENT),Double.parseDouble(scales_data[i].KEY_FAT_PERCENTAGE),sex));
				
				m_arrayadapter.add(map);

				
			}
			SimpleAdapter m_simpleadapter = new SimpleAdapter(context, m_arrayadapter,
					R.layout.listscaleslayout, new String[] { "time", "scales", "muscle","moisture","fat_percentage","calorie","bmr","body"}, new int[] {
							R.id.text_time, R.id.text_scales,R.id.text_muscle,R.id.text_moisture,R.id.text_fat_percentage,R.id.text_calorie,R.id.text_bmr,R.id.text_body});
			list.setAdapter(m_simpleadapter);
			
		}
	}
	public static String judgeBody(Context context,double muscle,double fat_percentage,String sex){
		String body="";
		if("M".equals(sex)){
			if( fat_percentage == 0){
				
			}else if(fat_percentage < 10){
//				if(muscle <= 30){
//					body = getResources(context,R.string.body_slim_type);
//				}else if(muscle <= 34 && muscle > 30){
//					body = getResources(context,R.string.body_slim_muscular);
//				}else if(muscle > 34){
//					body = getResources(context,R.string.body_muscular_type);
//				}
				body = getResources(context,R.string.body_slim);
			}else if(fat_percentage >= 10 && fat_percentage <= 20){
//				if(muscle <= 30){
//					body = getResources(context,R.string.body_run_insufficiency);
//				}else if(muscle <= 34 && muscle > 30){
//					body = getResources(context,R.string.body_standard);
//				}else if(muscle > 34){
//					body = getResources(context,R.string.body_muscular);
//				}
				body = getResources(context,R.string.body_standard);
			}else if(fat_percentage > 20 && fat_percentage <= 25){
//				if(muscle <= 30){
//					body = getResources(context,R.string.body_invisible_obese);
//				}else if(muscle <= 34 && muscle > 30){
//					body = getResources(context,R.string.body_obese);
//				}else if(muscle > 34){
//					body = getResources(context,R.string.body_overweight_type);
//				}
				body = getResources(context,R.string.body_over_weight);
			}else if(fat_percentage > 25){
				body = getResources(context,R.string.body_obese1);
			}
		}else{
			if( fat_percentage == 0){
				
			}else if(fat_percentage < 18){
//				if(muscle <= 25){
//					body = getResources(context,R.string.body_slim_type);
//				}else if(muscle <= 27 && muscle > 25){
//					body = getResources(context,R.string.body_slim_muscular);
//				}else if(muscle > 27){
//					body = getResources(context,R.string.body_muscular_type);
//				}
				body = getResources(context,R.string.body_slim);
			}else if(fat_percentage >= 18 && fat_percentage <= 28){
//				if(muscle <= 25){
//					body = getResources(context,R.string.body_run_insufficiency);
//				}else if(muscle <= 27 && muscle > 25){
//					body = getResources(context,R.string.body_standard);
//				}else if(muscle > 27){
//					body = getResources(context,R.string.body_muscular);
//				}

				body = getResources(context,R.string.body_standard);
			}else if(fat_percentage > 28 && fat_percentage <= 30){
//				if(muscle <= 25){
//					body = getResources(context,R.string.body_invisible_obese);
//				}else if(muscle <= 27 && muscle > 25){
//					body = getResources(context,R.string.body_obese);
//				}else if(muscle > 27){
//					body = getResources(context,R.string.body_overweight_type);
//				}

				body = getResources(context,R.string.body_over_weight);
			}else if(fat_percentage > 30){
				body = getResources(context,R.string.body_obese1);
			}
		}
		return body;
	}
	
	public static String getResources(Context context,int resources){
		return context.getResources().getString(resources);
	}
}
